import { Component, Input } from '@angular/core';
import { CascaderItem } from 'ng-devui';
@Component({
  selector: 'app-storehousecategory',
  templateUrl: './addstorehousecategory.component.html',
  styleUrls: ['./addstorehousecategory.component.scss']
})
export class AddStorehousecategoryComponent {
  @Input() data: any;
  options :any;//部门
  WarehouseCategory={
    warehouseCategoryName: '',
    parentWarehouseCategoryId: null,
  };//分类类目
  constructor(){}
  ngOnInit(): void{
    this.options = this.convertToCascaderItem(this.data.options)
    if(this.data.pathPids){
      this.WarehouseCategory.parentWarehouseCategoryId = this.data.pathPids[this.data.pathPids.length-1]
    }
  }
  convertToCascaderItem(data: any[]): CascaderItem[] {
    return data.map(item => {
      let cascaderItem: CascaderItem = {
        label: item.warehouseCategoryName,
        value: item.warehouseCategoryId,
      };
      if (item.subWarehouseCategories) {
        cascaderItem.children = this.convertToCascaderItem(item.subWarehouseCategories);
      }
      return cascaderItem;
    });
  }//转换数据格式为华为库练级菜单的数据格式
  onChanges($event: string | any[]){
    this.WarehouseCategory.parentWarehouseCategoryId = $event[$event.length-1]
  }
}
